package com.yzh.pinboard.CustomView;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;

import com.yzh.pinboard.R;

/**
 * Created by Administrator on 2017/3/14.
 */

public class EraserSettingView extends LinearLayout implements CompoundButton
        .OnCheckedChangeListener, SlideViewLayout.OnSlideListener {

    public EraserSettingView(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_eraser_setting, this);
        RadioButton eraserLine = (RadioButton) view.findViewById(R.id.rBtn_eraser_line);
        RadioButton eraserRect = (RadioButton) view.findViewById(R.id.rBtn_eraser_rect);
        SlideViewLayout slid = (SlideViewLayout) view.findViewById(R.id.slide);
        slid.setOnSlideListener(this);
        eraserLine.setOnCheckedChangeListener(this);
        eraserRect.setOnCheckedChangeListener(this);

    }

    public EraserSettingView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }


    public void setEraserListener(EraserListener eraserListener) {
        mEraserListener = eraserListener;
    }

    private EraserListener mEraserListener;

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        int i = buttonView.getId();
        if (mEraserListener == null) {
            return;
        }
        if (i == R.id.rBtn_eraser_line) {
            if (isChecked) {
                mEraserListener.onEraserLine();
            }
        } else if (i == R.id.rBtn_eraser_rect) {
            if (isChecked) {
                mEraserListener.onEraserRect();
            }
        }
    }

    @Override
    public void onSlideSuccess() {
        if (mEraserListener != null) {
            mEraserListener.onEraserAll();
        }
    }

    public interface EraserListener {
        void onEraserAll();

        void onEraserLine();

        void onEraserRect();
    }
}
